package com.ocom.xfrecode.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ocom.common.constant.UnifiendPayUrl;
import com.ocom.common.entity.card.EntityXfGoodListDishes;
import com.ocom.common.entity.card.EntityXfGoodListOrg;
import com.ocom.common.enums.ResultEnum;
import com.ocom.common.request.payconfig.mealorder.GetOrderDishesRequest;
import com.ocom.common.request.payconfig.mealorder.RefundOrderDishesRequest;
import com.ocom.common.request.ugcapi.OrderedShowRequest;
import com.ocom.common.request.web.GetPointMealSendReportsXMRequest;
import com.ocom.common.request.xfrecde.*;
import com.ocom.common.resp.Result;
import com.ocom.common.utils.ResultUtil;
import com.ocom.xfrecode.service.XfGoodListDishesService;
import com.ocom.xfrecode.service.XfGoodListOrgService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Description: TODO
 * @Author: 朱晖
 * @Date: 2023/5/4
 **/
@Slf4j
@RestController
public class GoodListController {

	@Autowired
	XfGoodListOrgService xfGoodListOrgService;

	/**
	 * 实体封装后的
	 */
	@Autowired
	XfGoodListDishesService xfGoodListDishesService;

	@PostMapping(UnifiendPayUrl.URL_saveXfGoodList)
	public Result saveXfGoodList(@RequestBody EntityXfGoodListOrg entityXfGoodListOrg){
		try {
			Boolean saveXfRecord=xfGoodListOrgService.sveXfGoodList(entityXfGoodListOrg);
			if (saveXfRecord){
				return ResultUtil.success();
			}else {
				return ResultUtil.error(ResultEnum.Err_2016);
			}
		}catch (Exception e){
			log.info("请求方式:【{}】,订单详情模块入库新增的数据:【{}】,异常信息:【{}】","消费订单的成功数据入库的模块入库失败",entityXfGoodListOrg,e);
			return ResultUtil.error(ResultEnum.Err_802);
		}
	}

	@PostMapping(UnifiendPayUrl.URL_saveXfGoodListBatch)
	public Result saveXfGoodListBatch(@RequestBody List<EntityXfGoodListOrg> list){
		try {
			Boolean saveXfRecord=xfGoodListOrgService.saveXfGoodListBatch(list);
			if (saveXfRecord){
				return ResultUtil.success();
			}else {
				return ResultUtil.error(ResultEnum.Err_2016);
			}
		}catch (Exception e){
			log.info("请求方式:【{}】,订单详情-批量保存-模块入库新增的数据:【{}】,异常信息:【{}】","消费订单的成功数据入库的模块入库失败",list,e);
			return ResultUtil.error(ResultEnum.Err_802);
		}
	}


	@PostMapping(UnifiendPayUrl.URL_getXfGoodList)
	public Result getXfGoodList(@RequestBody GetXfGoodListRequest request){
		return ResultUtil.success(xfGoodListOrgService.getXfGoodList(request));
	}


	@PostMapping(UnifiendPayUrl.URL_refundXfGoodList)
	public Result refund(@RequestBody RefundOrderDishesRequest request){
		return ResultUtil.success(xfGoodListOrgService.refundXfGoodList(request));
	}

	//11.4.3已点餐查询（getOrderDishes）
	@PostMapping(UnifiendPayUrl.URL_getOrderDishes)
	public Result getOrderDishes(@RequestBody GetOrderDishesRequest request){
		try {
			return  ResultUtil.success(xfGoodListDishesService.getOrderDishes(request));
		}catch (Exception e){
			e.printStackTrace();
			return  ResultUtil.info(500,e.getMessage());
		}

	}

	@PostMapping(UnifiendPayUrl.URL_getMealSendReportsXMByGoods)
	public Result getMealSendReportsXMByGoods(@RequestBody GetPointMealSendReportsXMRequest request){
		try {
			return  ResultUtil.success(xfGoodListDishesService.getMealSendReportsXMByGoods(request));
		}catch (Exception e){
			e.printStackTrace();
			return  ResultUtil.info(500,e.getMessage());
		}

	}

	//11.4.3B已点餐查询（getOrderDishesB）
	@PostMapping(UnifiendPayUrl.URL_getOrderDishesB)
	public Result getOrderDishesB(@RequestBody GetOrderDishesRequest request){
		try {
			return  ResultUtil.success(xfGoodListDishesService.getOrderDishesB(request));
		}catch (Exception e){
			e.printStackTrace();
			return  ResultUtil.info(500,e.getMessage());
		}

	}


	//11.4.4 获取用户已点餐餐段
	@PostMapping(UnifiendPayUrl.URL_getUserOrdered)
	public Result getUserOrdered(@RequestBody GetUserOrdered request){
		try {
			return  ResultUtil.success(xfGoodListDishesService.getUserOrdered(request));
		}catch (Exception e){
		    log.info("查询");
			return  ResultUtil.info(500,e.getMessage());
		}

	}

	@PostMapping(UnifiendPayUrl.URL_getOrderDishesDetail)
	public Result getOrderDishesDetail(@RequestBody OrderedShowRequest request){
		try {
			GetXfGoodListRequest goodListRequest = new GetXfGoodListRequest();
			goodListRequest.setComId(request.getComId());
			goodListRequest.setOrderNo(request.getOrderNo());
			goodListRequest.setMonthValue(request.getMonthValue());
			return  ResultUtil.success(xfGoodListOrgService.getXfGoodList(goodListRequest));
		}catch (Exception e){
		//	System.out.println(e);
			return  ResultUtil.info(500,e.getMessage());
		}
	}


	@PostMapping(UnifiendPayUrl.URL_getXfGoodListByPointId)
	public Result getXfGoodListByPointId(@RequestBody XfGoodListByPointIdRequest request){
		return ResultUtil.success(xfGoodListOrgService.getXfGoodListByPointId(request));
	}

	/**
	 * 备餐汇总报表
	 * @return
	 */
	@PostMapping(UnifiendPayUrl.URL_getMealPreReportsXM)
	public Result getMealPreReportsXM(@RequestBody GetMealPreReportsXMRequest reportsXMRequest){
		return ResultUtil.success(xfGoodListOrgService.getMealPreReportsXM(reportsXMRequest));
	}

	@PostMapping(UnifiendPayUrl.URL_getMealSendReportsXMByOne)
	public Result getMealSendReportsXMByOne (@RequestBody  GetMealSendReportsXMByOneRequest reportsXMByOneRequest){
		return ResultUtil.success(xfGoodListOrgService.getMealSendReportsXMByOne(reportsXMByOneRequest));
	}

	@PostMapping(UnifiendPayUrl.URL_getMealSendReportsXMByTwo)
	public Result getMealSendReportsXMByTwo(@RequestBody GetMealSendReportsXMByTwoRequest reportsXMByTwoRequest){
		return ResultUtil.success(xfGoodListOrgService.getMealSendReportsXMByTwo(reportsXMByTwoRequest));
	}


//	@PostMapping(UnifiendPayUrl.URL_getPointMealPre)
//	public Result getPointMealPre(@RequestBody GetPointMealPreReportsRequest request) throws Exception {
//		return ResultUtil.success(xfGoodListOrgService.getPointMealPre(request));
//	}

//	@PostMapping(UnifiendPayUrl.URL_getPointMealSend)
//	public Result getPointMealSend(@RequestBody GetPointMealSendReportsRequest request) throws Exception {
//		return ResultUtil.success(xfGoodListOrgService.getPointMealSend(request));
//	}



	//11.4.3B已点餐查询（getOrderDishesB）
	@PostMapping(UnifiendPayUrl.URL_getOrderDishesC)
	public Result getOrderDishesC(@RequestBody GetOrderDishesRequest request){
		try {
			return  ResultUtil.success(xfGoodListDishesService.getOrderDishesC(request));
		}catch (Exception e){
			e.printStackTrace();
			return  ResultUtil.info(500,e.getMessage());
		}

	}

	@PostMapping(UnifiendPayUrl.URL_getPerVideoList)
	public Result getPerVideoList(@RequestBody GetPerVideoListRequest getPerVideoListRequest){
		return this.xfGoodListOrgService.getPerVideoList(getPerVideoListRequest);
	}

	@PostMapping(UnifiendPayUrl.URL_updateGoodsById)
	public Result updateGoodsById(@RequestBody EntityXfGoodListOrg entityXfGoodListOrg){
		return ResultUtil.success(this.xfGoodListOrgService.updateById(entityXfGoodListOrg));
	}

	@PostMapping(UnifiendPayUrl.URL_updateChangeDishes)
	public Result updateChangeDishes(@RequestBody UpdateChangeDishesRequest request){
		return ResultUtil.success(this.xfGoodListOrgService.updateChangeDishes(request));
	}
}
